/*******************************************************************************
 * Copyright (c) 2014. konbluesky  (blackjackhoho@gmail.com)
 * Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 ******************************************************************************/

package com.fysports.web.model.system;

import com.jfinal.log.Log;
import com.fysports.web.kit.tree.ITreeRecursion;
import com.fysports.web.model.BaseModel;

import java.util.Date;
import java.util.List;


/**
 * Created by konbluesky
 * Date : 14-7-1 下午1:09
 * Project : simple.jiren
 */
public class SystemMenu extends BaseModel<SystemMenu> implements ITreeRecursion {
    private static Log log = Log.getLog(SystemMenu.class);
    public final static SystemMenu dao = new SystemMenu();
    /*数据库字段静态变量*/
    /** code  系统菜单设置 */
    public final static String COL_CODE="code";
    /** parentcode   */
    public final static String COL_PARENTCODE="parentcode";
    /** encode   */
    public final static String COL_ENCODE="encode";
    /** name   */
    public final static String COL_NAME="name";
    /** url   */
    public final static String COL_URL="url";
    /** isleaf   */
    public final static String COL_ISLEAF="isleaf";
    /** orders  排序 */
    public final static String COL_ORDERS="orders";
    /** uiicon   */
    public final static String COL_UIICON="uiicon";
    /** uihastip  开启悬浮提示 */
    public final static String COL_UIHASTIP="uihastip";
    /** remark   */
    public final static String COL_REMARK="remark";

    public SystemMenu() {
        if (this.getStr(COL_UUID) == null || this.getStr(COL_UUID).length() == 0) {
            this.set(COL_UUID, generateUUID());
        }
    }


    public SystemMenu(SystemMenu e) {
        this._setAttrs(e);
    }


    public List<SystemMenu> getParents() {
        String code = this.getStr("code");
        if (code.equals("0"))
            return null;
        return getParents(code);
    }


    /**
     * getNTChilds
     *
     * @param nodeid
     * @return
     */
    public List<SystemMenu> getParents(String nodeid) {
        String sql = "select * from " + getTable().getName()
                + " where liveflag=1 and FIND_IN_SET(code,getMenuParents('0',?)) order by orders asc";
        List<SystemMenu> list = SystemMenu.dao.find(sql, nodeid);
        return list;
    }


    /**
     * getNTParents
     *
     * @param nodeid
     * @return
     */
    public List<SystemMenu> getChilds(String nodeid) {
        String sql = "select * from " + getTable().getName()
                + " where liveflag=1 and FIND_IN_SET(code,getMenuChilds(?)) order by orders asc";
        List<SystemMenu> list = SystemMenu.dao.find(sql, nodeid);
        return list;
    }



    @Override public ITreeRecursion getInstance() {
        return new SystemMenu(this);
    }

    @Override
    public String getCode(){
        return this.getStr(COL_CODE);
    }
    public void setCode(String code){
        this.set(COL_CODE,code);
    }
    @Override
    public String getParentCode(){
        return this.getStr(COL_PARENTCODE);
    }
    public void setParentCode(String parentcode){
        this.set(COL_PARENTCODE,parentcode);
    }
    public String getEncode(){
        return this.getStr(COL_ENCODE);
    }
    public void setEncode(String encode){
        this.set(COL_ENCODE,encode);
    }
    @Override
    public String getName(){
        return this.getStr(COL_NAME);
    }
    public void setName(String name){
        this.set(COL_NAME,name);
    }
    public String getUrl(){
        return this.getStr(COL_URL);
    }
    public void setUrl(String url){
        this.set(COL_URL,url);
    }
    public String getLiveflag(){
        return this.getStr(COL_LIVEFLAG);
    }
    public void setLiveflag(String liveflag){
        this.set(COL_LIVEFLAG,liveflag);
    }
    public String getIsleaf(){
        return this.getStr(COL_ISLEAF);
    }
    public void setIsleaf(String isleaf){
        this.set(COL_ISLEAF,isleaf);
    }
    public String getOrders(){
        return this.getStr(COL_ORDERS);
    }
    public void setOrders(String orders){
        this.set(COL_ORDERS,orders);
    }
    public String getUiicon(){
        return this.getStr(COL_UIICON);
    }
    public void setUiicon(String uiicon){
        this.set(COL_UIICON,uiicon);
    }
    public String getUihastip(){
        return this.getStr(COL_UIHASTIP);
    }
    public void setUihastip(String uihastip){
        this.set(COL_UIHASTIP,uihastip);
    }
    public Date getCreatetime(){
        return this.getDate(COL_CREATETIME);
    }
    public void setCreatetime(Date createtime){
        this.set(COL_CREATETIME,createtime);
    }
    public String getRemark(){
        return this.getStr(COL_REMARK);
    }
    public void setRemark(String remark){
        this.set(COL_REMARK,remark);
    }

}
